package com.khalil.kkadmin.module.job;

import com.khalil.kkadmin.module.job.entity.KkJobTask;
import com.khalil.kkadmin.module.job.service.KkJobTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("job")
public class KkJobTaskController {
    @Autowired
    private KkJobTaskService jobTaskService;

    @GetMapping("/{id}")
    public KkJobTask getJob(@PathVariable("id") Long id) {
        return jobTaskService.getJobTaskById(id);
    }

    @GetMapping("list")
    public List<KkJobTask> getJobs(String keyword, String disabled, String jobType, String expressionType) {
        return jobTaskService.listJobTask(keyword, disabled, jobType, expressionType);
    }

    @PostMapping
    public void addJob(@RequestBody KkJobTask kkJobTask) {
        jobTaskService.addJobTask(kkJobTask);
    }

    @PutMapping
    public void updateJob(@RequestBody KkJobTask kkJobTask) {
        jobTaskService.updateJobTask(kkJobTask);
    }

    @DeleteMapping("/{id}")
    public void deleteJob(@PathVariable("id") Long id) {
        jobTaskService.deleteJob(id);
    }

    @PutMapping("/{id}/pause")
    public void pauseJob(@PathVariable("id") Long id) {
        jobTaskService.pauseJob(id);
    }

    @PutMapping("/{id}/resume")
    public void resumeJob(@PathVariable("id") Long id) {
        jobTaskService.resumeJob(id);
    }
}
